#include<iostream>
using namespace std;

void generateSpiralMatrix(int n) {
    int matrix[n][n];
    int num = 1;
    int startRow = 0, endRow = n - 1;
    int startCol = 0, endCol = n - 1;

    while (startRow <= endRow && startCol <= endCol) {
        for (int col = startCol; col <= endCol; col++) {
            matrix[startRow][col] = num++;
        }
        startRow++;

        for (int row = startRow; row <= endRow; row++) {
            matrix[row][endCol] = num++;
        }
        endCol--;

        for (int col = endCol; col >= startCol; col--) {
            matrix[endRow][col] = num++;
        }
        endRow--;
   
        for (int row = endRow; row >= startRow; row--) {
            matrix[row][startCol] = num++;
        }
        startCol++;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << matrix[i][j] << "\t";
        }
        cout << endl;
    }
}

int main() {
    generateSpiralMatrix(5);

    return 0;
}